package com.bnlr.lrparking.appui.stall;

import android.os.Bundle;
import android.widget.TextView;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.TextureMapView;
import com.baidu.mapapi.model.LatLng;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.base.BaseActivity;
import com.bnlr.lrparking.app.AppConfig;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by hp on 2017/12/5.
 * 小区周边地图
 */

public class PlotRimMapActivity extends BaseActivity {

    @BindView(R.id.plotrim_map)
    TextureMapView plotrim_map;
    @BindView(R.id.tv_nav_title)
    TextView tv_nav_title;
    private Unbinder unbinder;
    private double lat=0,lng=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_plotrimap);
        unbinder = ButterKnife.bind(this);
        lat=Double.valueOf(AppConfig.getInstance().getString("Latitude", ""));
        lng=Double.valueOf(AppConfig.getInstance().getString("Longitude", ""));
        initView();
    }

    private void initView(){
        tv_nav_title.setText("车位位置");
        setStall(lat,lng);
    }
    /**
     * 地图
     */
    private void setStall(double Lat,double Lng){
        //初始化地图
        BaiduMap mBaidumap = plotrim_map.getMap();
        //设定中心点坐标
        LatLng cenpt = new LatLng(Lat,Lng);
        //定义地图状态
        MapStatus mMapStatus = new MapStatus.Builder()
                .target(cenpt)
                .zoom(18)
                .build();

        //定义MapStatusUpdate对象，以便描述地图状态将要发生的变化
        MapStatusUpdate mMapStatusUpdate = MapStatusUpdateFactory.newMapStatus(mMapStatus);
        //改变地图状态
        mBaidumap.setMapStatus(mMapStatusUpdate);
        BitmapDescriptor bitmap = BitmapDescriptorFactory
                .fromResource(R.mipmap.plot_position);
        OverlayOptions option = new MarkerOptions()
                .position(cenpt)
                .icon(bitmap);
        mBaidumap.addOverlay(option);

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，实现地图生命周期管理
        plotrim_map.onDestroy();
        unbinder.unbind();
    }
    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView. onResume ()，实现地图生命周期管理
        plotrim_map.onResume();
    }
    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView. onPause ()，实现地图生命周期管理
        plotrim_map.onPause();
    }
}
